{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": "{'request_id': '1680247025,9b723916-077d-4060-ae28-e6b989081cae',\n 'time_used': 180,\n 'faces': [{'face_token': '0bd9005f2f2f07c4f64129f295fa6686',\n   'face_rectangle': {'top': 218, 'left': 195, 'width': 202, 'height': 202},\n   'attributes': {'gender': {'value': 'Female'},\n    'age': {'value': 37},\n    'emotion': {'anger': 2.695,\n     'disgust': 0.03,\n     'fear': 2.364,\n     'happiness': 94.877,\n     'neutral': 0.011,\n     'sadness': 0.011,\n     'surprise': 0.011},\n    'beauty': {'male_score': 64.36, 'female_score': 66.806}}}],\n 'image_id': 'z/QMl04zf8T/E98EQL9OkQ==',\n 'face_num': 1}"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('yyqx.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"api_key\":\"zQsh0EZmapcf8ur3Fu_bUGLEql3RMLnW\",\n",
    "    \"api_secret\":\"H8TGaWr4B2FmlTs6xsDtTKoYcFZwqOjr\",\n",
    "    \"image_base64\":img,\n",
    "    \"return_attributes\":\"gender,age,emotion,beauty\"\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print(response.status_code)\n",
    "response.json()\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: requests in d:\\python\\lib\\site-packages (2.28.2)Note: you may need to restart the kernel to use updated packages.\n",
      "\n",
      "Requirement already satisfied: certifi>=2017.4.17 in d:\\python\\lib\\site-packages (from requests) (2022.12.7)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\\python\\lib\\site-packages (from requests) (1.26.15)\n",
      "Requirement already satisfied: idna<4,>=2.5 in d:\\python\\lib\\site-packages (from requests) (3.4)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in d:\\python\\lib\\site-packages (from requests) (3.1.0)\n"
     ]
    }
   ],
   "source": [
    "pip install requests"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
